﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Services.Protocols;

namespace Hanhud.Web
{
    /// <summary>
    /// Summary description for HANHUDService
    /// </summary>
    [WebService(Namespace = "http://real-hanhud.com/WebService")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService()]
    [SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
    public class HANHUDService : System.Web.Services.WebService
    {
        [WebMethod()]
        [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
        public LocationCollection GetProvinces()
        {
            return CLocation.GetLocations();
        }

        [WebMethod()]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public LocationCollection GetDistricts(int provinceCode)
        {
            return CLocation.GetLocations(provinceCode);
        }
        [WebMethod()]
        [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
        public LocationCollection GetCommunes(int provinceCode, int districtCode)
        {
            return CLocation.GetLocations(provinceCode, districtCode);
        }

        [WebMethod()]
        [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
        public ProjectCollection GetProjectList(int provinceCode, int districtCode)
        {
            ProjectCollection collection = CProject.GetProjectList();

            ProjectCollection matches = new ProjectCollection();
            //matches.AddRange(collection.FindAll(delegate(CProject match)
            //{
            //    return
            //        provinceCode > 0 ?
            //        (districtCode > 0 ?
            //            (match.Location.ProvinceCode == provinceCode && match.Location.DistrictCode == districtCode) :
            //            match.Location.ProvinceCode == provinceCode) :
            //        false;
            //}));

            return matches;
        }
    }
}
